﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ProductDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack){
            Application.Remove("Discount");
            lblOrderID.Text = Application["OrderID"].ToString();
            ddlProductName.Focus();
        }
    }
    protected void ddlProductName_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlProductName.SelectedIndex > 0)
        {
            txtProductID.Text = ddlProductName.SelectedValue;
            if (ddlProductName.SelectedIndex == 1)
            {
                txtPrice.Text = "225.50";
            }
            else if (ddlProductName.SelectedIndex == 2)
            {
                txtPrice.Text = "41.25";
            }
            else
            {
                txtPrice.Text = "10.33";
            }
            txtQuantity.Focus();
        }
        else {
            txtProductID.Text = "";
            txtPrice.Text = "";
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        int quantity = Convert.ToInt32(txtQuantity.Text);
        if(quantity > 5){
            if (ddlProductName.SelectedIndex == 1) {
                Application["Discount"] = "25";
            }else if (ddlProductName.SelectedIndex == 2){
                Application["Discount"] = "15";
            }
            else if (ddlProductName.SelectedIndex == 3)
            {
                Application["Discount"] = "10";
            }
            else {
                Application.Remove("Discount");
            }
        }
        Application["ProductID"] = txtProductID.Text;
        Application["Price"] = txtPrice.Text;
        Application["Quantity"] = txtQuantity.Text;
        Response.Redirect("ShippingDetails.aspx");
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtQuantity.Text = "";
        txtProductID.Text = "";
        txtPrice.Text = "";
        ddlProductName.SelectedIndex = 0;
        ddlProductName.Focus();
    }
}